<!DOCTYPE html><head><title>ESP8266 light</title>
<script type="text/javascript" src="140medley.min.js"></script>
<script src="picker.js"></script>
<script type="text/javascript">

var xhr=j();
var sendInProgress=false;

function selectCol(colour) {
	var pwmJson={
		"period": 1000,
		"rgb": {
			"red": colour.rgb().r*64,
			"green": colour.rgb().g*64,
			"blue": colour.rgb().b*64
		}
	};

	if (sendInProgress) return;
	sendInProgress=true;
	xhr.open("POST", "config?command=light", true);
	xhr.onreadystatechange=function() {
		if (xhr.readyState==4) sendInProgress=false;
	}
	xhr.send(JSON.stringify(pwmJson));
}


function showPick() {
	var parent = document.getElementById('parent');
	var picker = new Picker({
		"arrow_size": 0,
		"parent": parent,
		"x": 0,
		"y": 0
		});
	picker.on_change=selectCol;
	picker.show();
}

window.onload=function(e) {
	showPick();
}

</script>
</head><body>
<ul>
<li><a href="wifi">WiFi setup</a></li>
</ul>
<p>Pick a color:</p>
<div id="parent"></div>

</body></html>
